{% extends "base.html" %}

{% block title %}
    首页
{% endblock %}

{% block style %}
    <script src="/static/lib/echarts/js/echarts.min.js"></script>
    <script src="/static/lib/sb-admin/vendor/jquery/jquery.min.js"></script>
{% endblock %}

{% block head %}
    <h1 class="page-header">首页</h1>
{% endblock %}

{% block content %}
    <div class="col-lg-12">
        <div id="show"></div>
        <div class="col-lg-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    公司新闻
                    <a class="pull-right" href="news.html">查看更多...</a>
                </div>
                <div class="panel-body">

                    <div class="col-lg-6"><a href="detail_news.html">优就业简介</a></div>
                    <div class="col-lg-6 text-right">2020-05-06 16:37:39</div>

                    <div class="col-lg-6"><a href="#">新闻99</a></div>
                    <div class="col-lg-6 text-right">2020-05-06 16:37:39</div>

                    <div class="col-lg-6"><a href="#">新闻98</a></div>
                    <div class="col-lg-6 text-right">2020-05-06 16:37:39</div>

                    <div class="col-lg-6"><a href="#l">新闻97</a></div>
                    <div class="col-lg-6 text-right">2020-05-06 16:37:39</div>

                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    考勤情况
                    <a class="pull-right" href="attendance_me.html">查看更多...</a>
                </div>
                <div class="panel-body">

                    <div class="col-lg-6">摔伤了，请假3天。</div>
                    <div class="col-lg-6 text-right">已驳回</div>

                    <div class="col-lg-6">住院5天</div>
                    <div class="col-lg-6 text-right">已通过</div>

                    <div class="col-lg-6">因家里有事，调休1天</div>
                    <div class="col-lg-6 text-right">已驳回</div>

                    <div class="col-lg-6">请年假1天</div>
                    <div class="col-lg-6 text-right">申请中</div>

                </div>
            </div>
        </div>
    </div>
    <script>
        var myChart = echarts.init(document.getElementById('show'));
        var option = {
            title: {
                text: '公司各部门职员人数统计'
            },
            tooltip: {},
            legend: {
                //data: ['职员人数']
            },
            xAxis: {
                data: ["人事部", "后勤部", "安保部", "市场部", "技术部", "新媒体部", "法务部", "董事会", "财务部"]
            },
            yAxis: {},
            series: [{
                name: '职员人数',
                type: 'bar', //柱状图
                data: [990, 0, 0, 907, 961, 943, 0, 1, 1001]
            }]
        };
        // myChart.setOption(option);

        $.ajax({
            url:"/demoapi",   //  请求地址
            data:"",  // 请求参数，常用于post 请求
            type:"get",  // 请求方式   get  post
            success:function (data) {  // 成功，被服务成功处理，
                // data 代表服务的返回值
                console.log(data.data);
                // 获取数据  绑定数据
                var x = option.xAxis.data = [];
                var y = option.series[0].data = [];
                for (var one in data.data){
                    x.push(data.data[one].name);
                    y.push(data.data[one].num);
                }
                console.log(x);
                console.log(y);

                //option.series[0].data = data.data; // 数组
                myChart.setOption(option);
            },
            error:function (error) {  // 失败，请求失败之后触发的方法
                // error 失败的信息
                console.log(error)
            }
        })

    </script>

{% endblock %}